﻿#region ... Copyright Notice ...
/*
   Copyright 2008 Tyler Jensen

	Author: Tyler Jensen    http://www.tsjensen.com/blog

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
#endregion

using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;

namespace Atrax.Configuration
{
	public class SpiderLimitConfigurationSection : ConfigurationSection
	{
		[ConfigurationProperty("hostPace")]
		public HostPaceConfigCollection HostPace
		{
			get
			{
				return ((HostPaceConfigCollection)(base["hostPace"]));
			}
		}
	}

	[ConfigurationCollectionAttribute(typeof(HostPaceConfigElement))]
	public class HostPaceConfigCollection : ConfigurationElementCollection
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new HostPaceConfigElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((HostPaceConfigElement)(element)).Name;
		}

		public void Add(HostPaceConfigElement element)
		{
			this.BaseAdd(element);
		}

		public void Remove(string key)
		{
			this.BaseRemove(key);
		}

		public void Clear()
		{
			this.BaseClear();
		}

		public HostPaceConfigElement this[int idx]
		{
			get { return (HostPaceConfigElement)BaseGet(idx); }
		}
	}

	public class HostPaceConfigElement : ConfigurationElement
	{
		public HostPaceConfigElement() { }
		public HostPaceConfigElement(string name, double seconds)
		{
			this.Name = name;
			this.Seconds = seconds;
		}

		[ConfigurationProperty("name", DefaultValue = "_", IsKey=true, IsRequired = true)]
		[StringValidator(InvalidCharacters = "~!@#$%^&()[]{}/;'\"|\\", MinLength = 1, MaxLength = 260)]
		public string Name
		{
			get
			{ return (string)this["name"]; }
			set
			{ this["name"] = value; }
		}

		[ConfigurationProperty("seconds", DefaultValue = 0.01, IsKey = false, IsRequired = true)]
		public double Seconds
		{
			get
			{ return (double)this["seconds"]; }
			set
			{ this["seconds"] = value.ToString(); }
		}
	}
}

